Hello world

Libraries that are used

#install.packages('dplyr')
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#install.packages('lubridate')
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
#install.packages('tidyr')
library(tidyr)
#install.packages('ggplot2')
library(ggplot2)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v tibble  3.0.5     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## v purrr   0.3.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x lubridate::as.difftime() masks base::as.difftime()
## x lubridate::date()        masks base::date()
## x dplyr::filter()          masks stats::filter()
## x lubridate::intersect()   masks base::intersect()
## x dplyr::lag()             masks stats::lag()
## x lubridate::setdiff()     masks base::setdiff()
## x lubridate::union()       masks base::union()
#install.packages('gganimate')
library(gganimate)
#install.packages('gifski')
library(gifski)
#install.packages('av')
library(av)
#install.packages('ggmap')
library(ggmap)
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
#install.packages('shiny')
library(shiny)
#install.packages('leaflet')
library(leaflet)

Reading the data

df_trees_orig <- read.csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-28/sf_trees.csv')

We create a copy of data to preserve its original form in case we want to look at it for reference

df_trees <- df_trees_orig

Data Cleaning

We look at the data structure, and see all the string variables are saved as char. We would rather have them as factors for potential modelling use.

str(df_trees)
## 'data.frame':    192987 obs. of  12 variables:
##  $ tree_id     : int  53719 30313 30312 30314 30315 30316 48435 30319 30318 30320 ...
##  $ legal_status: chr  "Permitted Site" "Permitted Site" "Permitted Site" "DPW Maintained" ...
##  $ species     : chr  "Tree(s) ::" "Tree(s) ::" "Tree(s) ::" "Pittosporum undulatum :: Victorian Box" ...
##  $ address     : chr  "2963 Webster St" "501 Arkansas St" "501 Arkansas St" "501 Arkansas St" ...
##  $ site_order  : int  1 3 2 1 5 6 4 2 1 3 ...
##  $ site_info   : chr  "Sidewalk: Curb side : Cutout" "Sidewalk: Curb side : Cutout" "Sidewalk: Curb side : Cutout" "Sidewalk: Curb side : Cutout" ...
##  $ caretaker   : chr  "Private" "Private" "Private" "Private" ...
##  $ date        : chr  "1955-09-19" "1955-10-20" "1955-10-20" "1955-10-20" ...
##  $ dbh         : int  NA NA NA 16 NA NA NA NA NA NA ...
##  $ plot_size   : chr  NA NA NA NA ...
##  $ latitude    : num  37.8 37.8 37.8 37.8 37.8 ...
##  $ longitude   : num  -122 -122 -122 -122 -122 ...

Changing columns with type character to type factor. you need double brackets because single bracket indexing returns a df object, which always evaluates to FALSE. Double brackets returns you the column as a vector whose data type can be tested. Alternatively, we can use single brackets but explicitly calling all rows and columns i.e [,i]

for (i in 1:12){ 
    if (is.character(df_trees[,i]) == TRUE) {
    df_trees[,i]<-as.factor(df_trees[,i])
  }
  }

date column has char data type. We change it to date.

# df_trees$date <- as.Date(df_trees$date,format="%Y-%m-%d") #using base r

df_trees$date <- lubridate::ymd(df_trees$date) #using lubridate

save the planted year of the tree as a separate column

# df_trees$year <- format(df_trees$date, "%Y")  #using base r

df_trees$year <- year(df_trees$date) # using lubridate
class(df_trees$year)
## [1] "numeric"

take a look at the format of species name in species column.

head(unique(df_trees$species))
## [1] Tree(s) ::                               
## [2] Pittosporum undulatum :: Victorian Box   
## [3] Acacia melanoxylon :: Blackwood Acacia   
## [4] Magnolia grandiflora :: Southern Magnolia
## [5] Corymbia ficifolia :: Red Flowering Gum  
## [6] Ginkgo biloba :: Maidenhair Tree         
## 571 Levels: :: ... Ziziphus jujuba :: Jujube

we see that for each species, the species column reports both the latin and common names. For future analysis, it might be more convenient to split the latin and common names into respective columns.

Separate the species column into latin and common name columns.

df_trees <- df_trees %>% 
  separate(species, sep = "::", remove = FALSE, into = c('species_lat', 'species_nor'))

Check the percentage of missing values in each column

for (col in colnames(df_trees)){
  print(paste(col, "=", mean(is.na(df_trees[[col]])))) #mean takes percentage here because adds up all TRUES (since their value is 1)
                                                       #and divides by total number of values (TRUE + FALSE)
}
## [1] "tree_id = 0"
## [1] "legal_status = 0.000279811593527025"
## [1] "species = 0"
## [1] "species_lat = 0"
## [1] "species_nor = 0"
## [1] "address = 0.00770518221434604"
## [1] "site_order = 0.00846689155228072"
## [1] "site_info = 0"
## [1] "caretaker = 0"
## [1] "date = 0.645691160544493"
## [1] "dbh = 0.216693352401975"
## [1] "plot_size = 0.259152170871613"
## [1] "latitude = 0.0146745635716395"
## [1] "longitude = 0.0146745635716395"
## [1] "year = 0.645691160544493"

Column with most significant amount of missing data is the date column.

We see almost every species has missing values (517 out of 571 species) so there is at least no clear indication that the data is missing not at random.

df_trees %>% filter(is.na(date))%>%
  select(species)%>%
  unique() %>% dim()
## [1] 517   1

further analysis of missing date values: percentage of observations with missing date values, per species.

df_trees_datena <- df_trees %>% filter(is.na(date)) %>% 
 count(species)
 
df_trees_species_count <- df_trees %>% count(species)

df_trees_merge <- dplyr::left_join(df_trees_species_count, df_trees_datena, by="species", suffix = c("total", "date.na"))
df_trees_merge$percent.missing <- df_trees_merge$ndate.na / df_trees_merge$ntotal
df_trees_merge %>%
  arrange(desc(ntotal), desc(percent.missing))
##                                                                               species
## 1                                                                          Tree(s) ::
## 2                                      Platanus x hispanica :: Sycamore: London Plane
## 3                                       Metrosideros excelsa :: New Zealand Xmas Tree
## 4                                               Lophostemon confertus :: Brisbane Box
## 5                                               Tristaniopsis laurina :: Swamp Myrtle
## 6                                              Pittosporum undulatum :: Victorian Box
## 7                                                    Prunus cerasifera :: Cherry Plum
## 8                                           Magnolia grandiflora :: Southern Magnolia
## 9                                          Arbutus 'Marina' :: Hybrid Strawberry Tree
## 10          Ficus microcarpa nitida 'Green Gem' :: Indian Laurel Fig Tree 'Green Gem'
## 11                             Prunus serrulata 'Kwanzan' :: Kwanzan Flowering Cherry
## 12                                             Acacia melanoxylon :: Blackwood Acacia
## 13                                                          Maytenus boaria :: Mayten
## 14                                                        Olea europaea :: Olive Tree
## 15                                            Corymbia ficifolia :: Red Flowering Gum
## 16                                          Callistemon citrinus :: Lemon Bottlebrush
## 17                                                   Ginkgo biloba :: Maidenhair Tree
## 18                                                Pyrus calleryana :: Ornamental Pear
## 19                                              Prunus serrulata :: Ornamental Cherry
## 20                                                Eriobotrya deflexa :: Bronze Loquat
## 21                                                    Ulmus parvifolia :: Chinese Elm
## 22                                                     Pinus radiata :: Monterey Pine
## 23                                                 Ligustrum lucidum :: Glossy Privet
## 24                                                  Pyrus kawakamii :: Evergreen Pear
## 25                                           Cupressus macrocarpa :: Monterey Cypress
## 26                                                                                 ::
## 27                  Tristaniopsis laurina 'Elegant' :: Small-leaf Tristania 'Elegant'
## 28                                              Pittosporum crassifolium :: Karo Tree
## 29                                                 Melaleuca quinquenervia :: Cajeput
## 30                                                Cordyline australis :: Dracena Palm
## 31                                                         Ficus nitida :: Laurel Fig
## 32                                                        Myoporum laetum :: Myoporum
## 33                                      Liquidambar styraciflua :: American Sweet Gum
## 34                                                     Juniperus chinensis :: Juniper
## 35                                                  Ficus retusa nitida :: Banyan Fig
## 36                                                              Tristania conferta ::
## 37                                                 Jacaranda mimosifolia :: Jacaranda
## 38                                              Lagunaria patersonii :: Primrose Tree
## 39                                       Schinus terebinthifolius :: Brazilian Pepper
## 40                                Eucalyptus polyanthemos :: Silver Dollar Eucalyptus
## 41                                           Washingtonia robusta :: Mexican Fan Palm
## 42                                                 Ficus microcarpa :: Chinese Banyan
## 43                                       Callistemon viminalis :: Weeping Bottlebrush
## 44                           Magnolia grandiflora 'Little Gem' :: Little Gem Magnolia
## 45                                               Agonis flexuosa :: Peppermint Willow
## 46                                     Phoenix canariensis :: Canary Island Date Palm
## 47                                                           Acer rubrum :: Red Maple
## 48                                               Syagrus romanzoffianum :: Queen Palm
## 49                                                         Ceratonia siliqua :: Carob
## 50                                        Laurus nobilis :: Sweet Bay: Grecian Laurel
## 51                                                Acacia baileyana :: Bailey's Acacia
## 52                   Rhaphiolepis Majestic Beauty :: Indian Hawthorn  'Majestic Beau'
## 53                                             Eucalyptus sideroxylon :: Red Ironbark
## 54                                       Crataegus phaenopyrum :: Washington Hawthorn
## 55                                                  Afrocarpus gracilior :: Fern Pine
## 56                                                   Arbutus unedo :: Strawberry Tree
## 57                                             Rhamnus alaternus :: Italian Buckthorn
## 58                                                Quercus agrifolia :: Coast Live Oak
## 59                           Pyrus calleryana 'Aristocrat' :: Aristocrat Callery Pear
## 60                                        Fraxinus uhdei :: Shamel Ash: Evergreen Ash
## 61                                                       Eucalyptus Spp :: Eucalyptus
## 62               Lyonothamnus floribundus subsp. asplenifolius :: Santa Cruz Ironwood
## 63                                     Leptospermum scoparium :: New Zealand Tea Tree
## 64                                                    Eucalyptus globulus :: Blue Gum
## 65                                            Crataegus laevigata :: English Hawthorn
## 66                                               Syzygium paniculatum :: Brush Cherry
## 67                                            Geijera parviflora :: Australian Willow
## 68                                 Platanus x hispanica 'Yarwood' :: Yarwood Sycamore
## 69                                                       Ulmus pumila :: Siberian Elm
## 70                                                  Pinus pinea :: Italian Stone Pine
## 71                                             Pistacia chinensis :: Chinese Pistache
## 72                                             Trachycarpus fortunei :: Windmill Palm
## 73                                                    Acer palmatum :: Japanese Maple
## 74                                     Leptospermum laevigatum :: Australian Tea Tree
## 75                                                       Dodonaea viscosa :: Hop Bush
## 76                                                  Acer buergeranum :: Trident Maple
## 77                                            Pinus canariensis :: Canary Island Pine
## 78                                                   Yucca gloriosa :: Spanish Dagger
## 79                     Magnolia grandiflora 'Samuel Sommer' :: Samuel Sommer Magnolia
## 80                                                         Taxus baccata :: Irish Yew
## 81                                 Dodonaea viscosa 'Purpurea' :: Purple Hopseed Bush
## 82                                       Melaleuca linariifolia :: Flaxleaf Paperbark
## 83                                                 Schinus molle :: California Pepper
## 84                                              Sequoia sempervirens :: Coast Redwood
## 85                                                            Fraxinus spp :: Ash Spp
## 86                                     Photinia fraseri :: Photinia: Chinese photinia
## 87                                         Populus nigra 'Italica' :: Lombardy Poplar
## 88                                            Acacia stenophylla :: Shoestring Acacia
## 89                                              Liriodendron tulipifera :: Tulip Tree
## 90                          Ceanothus 'Ray Hartman' :: California Lilac 'Ray Hartman'
## 91                                    Pittosporum tenuifolium :: Tawhiwhi Pittosporum
## 92                                                 Prunus blireiana :: Flowering Plum
## 93                           Magnolia grandiflora 'Saint Mary' :: Saint Mary Magnolia
## 94                                                    Ulmus americana :: American Elm
## 95                                         Fraxinus oxycarpa 'Raywood' :: Raywood Ash
## 96                                               Prunus x yedoensis :: Yoshino Cherry
## 97          Prunus cerasifera 'Krauter vesuvius' :: Purple Leaf Plum Krauter Vesuvius
## 98                                        Koelreuteria paniculata :: Golden Rain Tree
## 99                                            Melaleuca ericifolia :: Heath Melaleuca
## 100                                                             Pinus Spp :: Pine Spp
## 101                                           Cupaniopsis anacardioides :: Carrotwood
## 102                                      Olea europaea 'Fruitless' :: Fruitless Olive
## 103                                                         Quercus suber :: Cork Oak
## 104                                           Magnolia doltsopa :: Himalayan Magnolia
## 105                                               Podocarpus macrophyllus :: Yew Pine
## 106                                                  Podocarpus gracilor :: Fern Pine
## 107                                              Celtis sinensis :: Chinese Hackberry
## 108                             Robinia x ambigua 'Purple Robe' :: Purple Robe Locust
## 109                                      Chamaerops humilis :: Mediterranean Fan Palm
## 110              Pyrus calleryana 'Chanticleer' :: Ornamental Pear Tree 'Chanticleer'
## 111                          Eucalyptus nicholii :: Nichol's Willow-Leafed Peppermint
## 112                                                              Ulmus spp :: Elm Spp
## 113                                      Prunus domestica 'Mariposa' :: Mariposa Plum
## 114                                              Eriobotrya japonica :: Edible Loquat
## 115                                                Acacia longifolia :: Golden Wattle
## 116                                         Cupressus sempervirens :: Italian Cypress
## 117                          Pyrus calleryana 'Bradford' :: Ornamental Pear: Bradford
## 118                                            Ligustrum japonicum :: Japanese Privet
## 119                                            Betula pendula :: European White Birch
## 120                                                    Cotoneaster SPP :: Cotoneaster
## 121                                                 Acer x freemanii :: Freeman Maple
## 122                                Ginkgo biloba 'Autumn Gold' :: Ginkgo: Autumn Gold
## 123                    Agonis flexuosa 'After Dark' :: Peppermint willow 'After Dark'
## 124                                                    Cedrus deodara :: Deodar Cedar
## 125                                                              Prunus spp :: Cherry
## 126                                   Ulmus parvifolia 'Drake' :: Drake's Chinese Elm
## 127                                                Tilia cordata :: Littleleaf Linden
## 128                                      Cupressocyparis leylandii :: Leyland Cypress
## 129                                                 Pittosporum eugenioides :: Tarata
## 130                                  Magnolia grandiflora 'Russet' :: Russet Magnolia
## 131                                Thuja occidentalis 'Emerald' :: Emerald Arborvitae
## 132                                             Melaleuca nesophila :: Pink Melaleuca
## 133                                                 Citrus spp :: Lemon: Orange: Lime
## 134                                                         Quercus ilex :: Holly Oak
## 135                          Malus floribunda :: Showy Crab Apple: Japanese Crabapple
## 136                                                 Ceanothus Sps :: California lilac
## 137                                                Hymenosporum flavum :: Sweet Shade
## 138                                               Cinnamomum camphora :: Camphor Tree
## 139                                                 Photinia fraseri :: Photinia Tree
## 140                              Prunus cerasifera 'Atropurpurea' :: Purple-Leaf Plum
## 141              Leptospermum scoparium 'Ruby Glow' :: New Zealand Ruby Glow Tea Tree
## 142                                           Arecastrum romanzoffianum :: Queen Palm
## 143                           Olea europaea 'Wilsonii' :: Wilson Olive Semi-fruitless
## 144                                                               Malus :: Crab Apple
## 145                                                       Robinia x ambigua :: Locust
## 146                                                                    Shrub :: Shrub
## 147                                           Aesculus x carnea :: Red Horse Chestnut
## 148                                                   Brahea edulis :: Guadalupe Palm
## 149                                                          Acacia spp :: Acacia Spp
## 150                                       Acer rubrum 'Red Sunset' :: Red Swamp Maple
## 151                                           Pinus thunbergii :: Japanese Black Pine
## 152                                         Pittosporum tobira :: Japanese Mockorange
## 153                     Platanus x hispanica 'Columbia' :: Columbia Hybrid Plane Tree
## 154                                                      Syzygium australe :: Eugenia
## 155                                                          Fraxinus oxycarpa :: Ash
## 156                                              Lagerstroemia indica :: Crape Myrtle
## 157                                             Gleditsia triacanthos :: Honey Locust
## 158                                             Rhaphiolepis indica :: India Hawthorn
## 159                                                  Corymbia maculata :: Spotted Gum
## 160                                                Grevillea robusta :: Silk Oak Tree
## 161                                         Melaleuca styphelliodes :: Paperbark Tree
## 162                                                      Morus alba :: White Mulberry
## 163                                                 Eucalyptus lehmanni :: Bushy Yate
## 164                                                          Magnolia spp :: Magnolia
## 165                                                      Ceiba speciosa :: Silk floss
## 166                                                Fraxinus americana :: American Ash
## 167                                                            Pyrus spp :: Pear Tree
## 168                                      Liquidambar orientalis :: Oriental Sweet Gum
## 169                                                       Magnolia champaca :: Champa
## 170                                                   Brugmansia spp :: Angel trumpet
## 171                                              Hakea suaveolens :: Sweet Hakea Tree
## 172                                         Eucalyptus camaldulensis :: River Red Gum
## 173                                                         Crateagus spp :: Hawthorn
## 174                                             Cercis occidentalis :: Western Redbud
## 175                                                       Persea americana :: Avocado
## 176                              Pyrus calleryana 'New Bradford' :: New Bradford Pear
## 177                                    Acer rubrum 'Armstrong' :: Armstrong Red Maple
## 178                                                           Olea Majestic Beauty ::
## 179                                                  Acer saccharinum :: Silver Maple
## 180                                                Zelkova serrata :: Sawleaf Zelkova
## 181                                                               Betula spp :: Birch
## 182                                                                     Ficus Spp. ::
## 183                                         Magnolia x soulangiana :: Saucer Magnolia
## 184                                  Elaeocarpus decipiens :: Japanese Blueberry Tree
## 185                                             Carpinus betulus :: European Hornbeam
## 186                                          Platanus racemosa :: California Sycamore
## 187                                        Aesculus californica :: California Buckeye
## 188                       Liquidambar styraciflua 'Rotundiloba' :: Roundleaf sweetgum
## 189                                                  Heteromeles arbutifolia :: Toyon
## 190                                                  Potential Site :: Potential Site
## 191                                           Albizia julibrissin :: Mimosa Silk Tree
## 192                                           Quercus virginiana :: Southern Live Oak
## 193                                                 Ilex aquifolium :: European Holly
## 194                                                         Ilex spp :: Holly Species
## 195                                     Araucaria heterophylla :: Norfolk Island Pine
## 196                                                Pittosporum spp :: Pittosporum spp
## 197                                                  Phoenix dactylifera :: Date Palm
## 198                                Ilex altaclarensis 'Wilsonii' :: Wilson Holly Tree
## 199                                             Calocedrus decurrens :: Incense Cedar
## 200                                                   Cedrus atlantica :: Atlas Cedar
## 201                                        Casuarina cunninghamiana :: Horsetail pine
## 202                                                    Melaleuca spp :: Melaleuca spp
## 203                Olea europaea 'Majestic Beauty' :: Majestic Beauty Fruitless Olive
## 204                                           Tibochina urvilleana :: Princess Flower
## 205                                                           Prunus persica :: Peach
## 206                              Eriobotrya deflexa 'Coppertone' :: Coppertone Loquat
## 207                                                        Ficus carica :: Edible Fig
## 208                                                  Alnus rhombifolia :: White Alder
## 209                                            Azara microphylla :: Little-Leaf Azara
## 210 Leptospermum scoparium  'Helene Strybing' :: Helene Strybing New Zealand Tea Tree
## 211                                      Washingtonia filifera :: California Fan Palm
## 212                Magnolia grandiflora 'Majestic Beauty' :: Majestic Beauty Magnolia
## 213                                               Cercis canadensis :: Eastern Redbud
## 214                                              Laurus x 'Saratoga' :: Hybrid Laurel
## 215                                                  Palm (unknown Genus) :: Palm Spp
## 216                                   Eucalyptus leucoxylon mac 'Rosea' :: Yellow Gum
## 217                                      Koelreuteria bipinnata :: Chinese Flame Tree
## 218                                                     Dracaena draco :: Dragon Tree
## 219                                         Acacia decurrens :: Acacia: Silver Wattle
## 220                                              Ulmus 'Prospector' :: Prospector Elm
## 221                                       Ginkgo biloba 'Fairmont' :: Fairmont Ginkgo
## 222                                                 Yucca elephantipes :: Giant Yucca
## 223                                                       Nerium oleander :: Oleander
## 224                                         Cassia leptophylla :: Gold Medallion Tree
## 225                  Fraxinus americana 'Autumn Purple' :: American Autumn Purple Ash
## 226                                      Araucaria columnaris :: Coral reef araucaria
## 227                                                  Prunus lyonii :: Catalina Cherry
## 228                            Acer rubrum 'October Glory' :: Red October Glory Maple
## 229                   Ginkgo biloba 'Princeton Sentry' :: Princeton Sentry Maidenhair
## 230                                              Ficus rubiginosa :: Port Jackson Fig
## 231                                             Prunus laurocerasus :: English laurel
## 232                                                      Prunus spp :: Flowering Plum
## 233                           Pyracantha  'Santa Cruz' :: Firethorn Tree 'Santa Cruz'
## 234                                               Acer macrophyllum :: Big Leaf Maple
## 235                                    Prunus subhirtella 'Pendula' :: Weeping Cherry
## 236                                                         Populus spp :: Poplar Spp
## 237                                    Casurina stricta :: Beefwood: Drooping She-Oak
## 238                                      Prunus caroliniana :: Carolina Cherry Laurel
## 239                                          Corymbia citriodora :: Lemon Scented Gum
## 240                                                           Picea Spp :: Spruce Spp
## 241                             Acer palmatum 'Bloodgood' :: Bloodgood Japanese Maple
## 242                                           Celtis occidentalis :: Common Hackberry
## 243                                                  Acer japonicum :: Japanese Maple
## 244                                              Pseudotsuga menziesii :: Douglas Fir
## 245                                              Robinia pseudoacacia :: Black Locust
## 246                                                               Salix spp :: Willow
## 247                                                                 Acer spp :: Maple
## 248                                                    Acacia cognata :: River Wattle
## 249                                                   Pinus halepensis :: Allepo Pine
## 250                                               Ficus macrophylla :: Morton Bay Fig
## 251                                                 Eucalyptus viminalis :: Manna Gum
## 252                                                       Prunus armeniaca :: Apricot
## 253                                 Acacia baileyana 'Purpurea' :: Purple-leaf Acacia
## 254                                                          Quercus rubra :: Red Oak
## 255                           Prunus x yedoensis 'Akebono' :: Daybreak Yoshino Cherry
## 256                           Cercis canadensis 'Forest Pansy' :: Forest Pansy Redbud
## 257         Magnolia grandiflora 'D.D. Blanchard' :: D.D. Blanchard Southern Magnolia
## 258                               Eucalyptus pulverulenta :: Silver Mountain Gum Tree
## 259                                           Prunus ilicifoia :: Holly-leaved Cherry
## 260                                                     Bambusa spp :: Bamboo Species
## 261                                               Nyssa sylvatica :: Tupelo: Sour Gum
## 262                                                    Alnus cordata :: Italian Alder
## 263                                            Quillaja saponaria :: Chilean Soapbark
## 264                                       Archontophoenix cunninghamiana :: King Palm
## 265                                            Celtis australis :: European Hackberry
## 266                                              Eucalyptus robusta :: Swamp mahogany
## 267                                          Fremontodendron spp :: Flannel Bush Tree
## 268                                                                Quercus spp :: Oak
## 269                          Ulmus carpinifolia 'Frontier' :: Frontier Elm 'Frontier'
## 270                                                     Pinus muricata :: Bishop Pine
## 271                                                 Fagus sylvatica :: European Beech
## 272                                                 Fraxinus x Moraine :: Moraine Ash
## 273                                            Dicksonia antarctica :: Soft Tree Fern
## 274                                        Umbellularia californica :: California Bay
## 275                                                  Cussonia spicata :: Cabbage tree
## 276                                    Podocarpus henkelii :: Long-Leafed Yellow-Wood
## 277                                                       Betula nigra :: River Birch
## 278                                                                   Ficus laurel ::
## 279                                                      Quercus lobata :: Valley Oak
## 280                                Aesculus x carnea 'Briotii' :: Ruby Horse Chestnut
## 281                                                   Quercus coccinea :: Scarlet Oak
## 282                    Pyrus calleryana 'Redspire' :: Ornamental Pear Tree 'Redspire'
## 283                                                Salix babylonica :: Weeping Willow
## 284                        Platanus x hispanica 'Bloodgood' :: Bloodgood London Plane
## 285                                                    Private shrub :: Private Shrub
## 286                                   Styphnolobium japonicum :: Chinese scholar tree
## 287                                                      Rhus lancea :: African Sumac
## 288                                                       Persea indica :: Indian Bay
## 289                                    Salix matsudana 'Tortuosa' :: Corkscrew Willow
## 290                                                         Chitalpa tashkentensis ::
## 291                                                  Acacia cyclops :: Cyclops wattle
## 292                                        Ligustrum ovalifolium :: California privet
## 293                                               Araucaria araucana :: Monkey puzzle
## 294                                    Cotinus coggygria 'Royal Purple' :: Smoke tree
## 295                                    Prunus serrulata 'Akebono' :: 'Akebono' Cherry
## 296                                                                         Privet ::
## 297                                      Metasequoia glyplostroboides :: Dawn Redwood
## 298                                    Eucalyptus microtheca :: Flooded Box: Coolibah
## 299                                              Populus tremuloides :: Quaking aspen
## 300                                                 Salix lasiolepis :: Arroyo willow
## 301                                             Banksia integrifolia :: Coast Banksia
## 302                                                        Prunus amygdalus :: Almond
## 303                               Citrus × meyeri 'Improved' :: Improved Meyer Lemon
## 304                                             Brachychiton populneus :: Bottle Tree
## 305                                                 Hymenosporum flavum :: Sweetshade
## 306                                                  Quercus tomentella :: Island oak
## 307                                      Ginkgo biloba 'Saratoga' :: Ginkgo: Saratoga
## 308                            Ulmus parvifolia 'Sempervirens' :: Weeping Chinese Elm
## 309                                           Albizia distachya :: Plume Albizia Tree
## 310                                               Eucalyptus melliodora :: Yellow Box
## 311                                                                Musa spp :: Banana
## 312                                        Sequoiadendron giganteum :: Sierra Redwood
## 313                                     Aesculus hippocastanum :: White Horsechestnut
## 314                                                  Howea forsteriana :: Kentia Palm
## 315                                                Olea europaea 'Swan Hill' :: Olive
## 316                        Carpinus betulus 'Fastigiata' :: Upright European Hornbeam
## 317                                                 Cornus florida :: Eastern Dogwood
## 318                        Liquidambar styraciflua 'Palo Alto' :: Palo Alto Sweet Gum
## 319                                       Cedrus atlantica Glauca :: Blue Atlas Cedar
## 320                                      Cryptomeria japonica :: Japanese Cryptomeria
## 321                                            Cupressus arizonica :: Arizona Cypress
## 322                                         Fraxinus velutina 'Glabra' :: Arizona Ash
## 323                                                  Juglans regia :: Walnut: English
## 324                                                     Dypsis cabadae :: Cabada palm
## 325                                                Thuja plicata :: Western Red Cedar
## 326                                      Eucalyptus cinerea :: Ash-colored Eucalyptus
## 327                                        Eucalyptus rudis :: Swamp Gum: Flooded Gum
## 328                                                Tilia americana :: Basswood Linden
## 329                                                            Corymbia calophylla ::
## 330                                                       Vitex lucens :: Puriri tree
## 331                                                                Yucca spp :: Yucca
## 332                                                     Psidium guajava :: Guava tree
## 333                                                            Solanum rantonnetti ::
## 334                                             Ailanthus altissima :: Tree Of Heaven
## 335                                                        Aloe barberae :: Tree aloe
## 336                 Gleditsia triacanthos 'Shademaster' :: Honey Locust 'Shademaster'
## 337                                     Citrus aurantifolia 'Bearss' :: Seedless Lime
## 338                                                      Quercus robur :: English Oak
## 339                                                   Fraxinus ornus :: Flowering Ash
## 340                                Grevillea 'Red Hooks' :: Silk Oak Tree 'Red Hooks'
## 341                                             Juglans nigra :: Eastern black walnut
## 342                                                      Populus alba :: White Poplar
## 343                                                             Cornus SPP :: Dogwood
## 344                                 Brachychiton acerifolius :: Australian Flame Tree
## 345                                                  Grevillea spp :: Silkoak species
## 346                                                      Quercus palustris :: Pin Oak
## 347                                                   Griselinia lucida :: Griselinia
## 348                               Prunus serrulata 'Mt. Fuji' :: Mt. Fuji Cherry Tree
## 349               Prunus cerasifera 'Thundercloud' :: Purple-Leaf Plum 'Thundercloud'
## 350                                                  Hakea laurina :: Sea Urchin Tree
## 351                 Prunus serrulata 'Amanagawa' :: Flowering Cherry Tree 'Amanagawa'
## 352                                    Malus x 'Callaway' :: White-Flowered Crabapple
## 353         Prunus serrulata 'Royal Burgundy' :: Royal Burgundy Flowering Cherry Tree
## 354                                       Juniperus californica :: California juniper
## 355                                             Phoenix roebelenii :: Pigmy Date Palm
## 356                                  Sophora japonica 'Regent' :: Regent Scholar Tree
## 357                                                  Persea borbonia :: False Avocado
## 358                                              Prunus spp 'Purpurea' :: Cherry Plum
## 359                         Ginkgo biloba 'Autumn Sentinel' :: Autumn Sentinel Ginkgo
## 360                                               Brahea aramata :: Mexican Blue Palm
## 361                                          Prunus x 'Amanogawa' :: Flowering Cherry
## 362                                        Quercus frainetto 'Trump' :: Hungarian Oak
## 363                                        Ficus microcarpa 'Retusa' :: Pot Belly Fig
## 364                  Pyrus calleryana 'Cleveland' :: Ornamental Pear Tree 'Cleveland'
## 365                                          Taxodium mucronatum :: Montezuma Cypress
## 366                                                             Syringa :: Lilac Tree
## 367                                                 Magnolia x alba :: White Champaca
## 368                                  Prunus domestica 'Santa Rosa' :: Santa Rosa Plum
## 369                                      New Zealand Tea Tree :: New Zealand Tea Tree
## 370                                 Leptospermum petersonii :: Lemon Scented Tea Tree
## 371                      Pyrus calleryana 'Capital' :: Ornamental Pear Tree 'Capital'
## 372                         Gleditsia triacanthos 'Sunburst' :: Sunburst Honey Locust
## 373                 Leptospermum scoparium 'Snow White' :: New Zealand White Tea Tree
## 374                                                          Chamaecyparis species ::
## 375                                Chiranthodendron pentadactylon :: Monkey Hand Tree
## 376                                    Juglans californica :: Walnut: Black (s.calif)
## 377                                                    Salix discolor :: Pussy Willow
## 378                             Viburnum odoratissimum var. awabuki :: Sweet viburnum
## 379                                             Jubaea chilensis :: Chilean Wine Palm
## 380                                        Phoenix spp :: Date palm (species unknown)
## 381                         Punica granatum 'Wonderfu :: Pomegranate Tree 'Wonderful'
## 382                                               Schefflera species :: Umbrella tree
## 383                                               Sophora japonica :: Japanese Pagoda
## 384                                           Archontophoenix myolensis :: Myola palm
## 385 Cornus nuttallii x florida 'Eddie's White Wonder' :: Eddie's White Wonder Dogwood
## 386                                                  Ulmus 'Frontier' :: Frontier Elm
## 387                                Auranticarpa rhombifolia :: Queensland Pittosporum
## 388                                        Fraxinus angustifolia :: Narrow-leaved Ash
## 389                                Pinus thunbergii 'Thunderhead' :: Thunderhead Pine
## 390                                              Abutilon hybridum :: Flowering maple
## 391                                           Acca sellowiana :: Pineapple Guava Tree
## 392                                             Acer pseudoplatanus :: Sycamore Maple
## 393                          Arctostaphylos manzanita 'Dr Hurd' :: Dr. Hurd Manzanita
## 394                                             Eucalyptus saligna :: Sidney Blue Gum
## 395                                    Populus trichocarpa :: Black Cottonwood Poplar
## 396                                                      Rhopalostylis baueri :: Palm
## 397                                                     Acer circinatum :: Vine Maple
## 398                                                      Butia capitata :: Pindo Palm
## 399                                           Rhamnus californica :: Coffeeberry Tree
## 400                                                Sapium sebiferum :: Chinese Tallow
## 401                                       Tilia americana 'Redmond' :: Redmond Linden
## 402                                         Chionanthus retusa :: Chinese Fringe Tree
## 403                                                       Diospyros kaki :: Persimmon
## 404                                             Leucodendron argenteum :: Silver Tree
## 405                                           Quercus wislizenii :: Interior Live Oak
## 406                                             Fraxinus holotricha :: Holotricha Ash
## 407                                                  Acacia dealbata :: Silver Wattle
## 408                                                         Acer negundo :: Box Elder
## 409                                       Callistemon 'Jeffers' :: Purple bottlebrush
## 410                                     Chamaecyparis lawsoniana :: Port Orford Cedar
## 411                                            Chamaecyparis obtusa :: Hinoki cypress
## 412                                             Escallonia bifida :: White escallonia
## 413                                         Eucalyptus macarthuri :: Camden Wollybutt
## 414                                        Juglans hindsii :: Walnut: Black (n.calif)
## 415                                        Juniperus silicicola :: Southern red cedar
## 416                                     Leucadendron 'Gold Strike' :: Yellow conebush
## 417                                                    Melia azerdarach :: Chinaberry
## 418                                                    Pinus coulteri :: Coulter pine
## 419                                      Prunus lusitanica :: Portugese Cherry Laurel
## 420                                                   Fortunella margarita :: Kumquat
## 421                             Garrya elliptica 'Evie' :: Evie Coast Silktassel Tree
## 422                                                   Metrosideros excelsa 'Aurea' ::
## 423                                                         Quercus alba :: White oak
## 424                                              Quercus engelmannii :: Engelmann oak
## 425                                            Radermachera sinica :: China Doll Tree
## 426                                              Sambucus mexicana :: Blue Elderberry
## 427                                                      Tecoma stans :: Trumpet bush
## 428                              Caryota maxima 'Himalaya' :: Himalayan Fishtail Palm
## 429                                                         Malus sylvestris :: Apple
## 430                     Acer x freemanii 'Autumn Blaze' :: Autumn Blaze Freeman Maple
## 431                                                     Quercus douglasii :: Blue Oak
## 432                   Crataegus laevigata 'Paul's Scarlet' :: Paul's Scarlet Hawthorn
## 433                                                 Malus 'Gala' :: Apple Tree 'Gala'
## 434                    Malus floribunda 'Prairie Fire' :: Prairie Fire Crabapple Tree
## 435                                             Populus canadensis :: Canadian Poplar
## 436                                                    Acacia vestita :: Hairy wattle
## 437                                 Arbutus unedo 'Compacta' :: Dwarf strawberry tree
## 438                                             Beaucarnea recurvata :: Ponytail palm
## 439                                              Chorisia speciosa :: Silk Floss Tree
## 440                                               Eucalyptus longifolia :: Woollybutt
## 441                                                  Fraxinus velutina :: Modesto Ash
## 442                 Garrya elliptica 'James Roof' :: James Roof Coast Silktassel Tree
## 443                                            Leptospermum quinquenervia :: Tea Tree
## 444                                                 Paulownia fortunei :: Dragon tree
## 445                                            Phoenix reclinata :: Senegal date palm
## 446                              Robinia pseudoacacia 'Umbraculifera' :: Globe Locust
## 447                                                         Ziziphus jujuba :: Jujube
## 448                                                      Ilex opaca :: American Holly
## 449                                        Platanus occidentalis :: American sycamore
## 450                                      Corynocarpus laevigata :: New Zealand Laurel
## 451                          Liquidambar styraciflua 'Festival' :: Festival Sweet Gum
## 452                                Magnolia sargentiana 'Robusta' :: Robusta Magnolia
## 453                                                Prunus serrula :: Birchbark Cherry
## 454                                                               Tilia spp :: Linden
## 455                                 Ulmus parvifolia 'Athena' :: Chinese Elm 'Athena'
## 456                         Aesculus x carnea 'O'Neill' :: O'Neill Red Horse Chestnut
## 457                               Magnolia x foggii 'Jack Fogg' :: Jack Fogg Michelia
## 458                                          Quercus keloggii :: California Black Oak
## 459                        Rhamnus alaternus 'John Edwards' :: John Edwards Buckthorn
## 460                                                  Tilia tomentosa :: Silver Linden
## 461                                                Acacia iteaphylla :: Willow wattle
## 462                                               Angohpora spp. :: Angophora species
## 463                                              Arbutus menziesii :: Pacific Madrone
## 464                                                          Brachychiton discolor ::
## 465                                 Brachychiton rupestris :: Narrow-leaf bottle tree
## 466                                                 Brahea armata :: Blue hesper palm
## 467                                   Ceanothus thyrsiflorus :: Blueblossom Ceanothus
## 468                                                 Corylus colurna :: Hazel: Turkish
## 469                                                       Cycas revoluta :: Sago palm
## 470                                                    Erythrina caffra :: Coral tree
## 471                                 Eucalyptus citriodora :: Lemon scented eucalyptus
## 472                                                    Eucalyptus gunnii :: Cider Gum
## 473                                      Eucalyptus simmondsi :: Simmond's Peppermint
## 474                                                  Eucalyptus torquata :: Coral Gum
## 475                                       Fraxinus uhdei 'Tomlinson' :: Tomlinson Ash
## 476                             Gleditsia triacanthos 'Aurea' :: Honey Locust 'Aurea'
## 477                                                Lithocarpus densiflorus :: Tan Oak
## 478                        Magnolia x soulangiana 'Rustica Rubra' :: Chinese Magnolia
## 479                                            Meryta sinclairii :: Puka or puke tree
## 480                                                      Morus rubra :: Red mulbeerry
## 481                                                      Pinus contorta :: Shore Pine
## 482                                         Platanus orientalis :: Eastern Plane Tree
## 483    Prunus serrulata 'Double Pink Weeping' :: Weeping Double Pink Flowering Cherry
## 484                                                    Sambucus species :: Elderberry
## 485                                          Schinus polygamus :: Chilean pepper tree
## 486                                        Styrax japonicus :: Japanese Snowdrop Tree
## 487                                                  Xylosma congestum :: Brush holly
## 488                                     Citrus × limon 'Lisbon' :: Lisbon Lemon Tree
## 489                                              Eucalyptus odorata :: Peppermint Box
## 490                            Lagerstroemia indica 'Natchez' :: Natchez Crape Myrtle
## 491                                               Paulownia tomentosa :: Empress Tree
## 492                                     Prunus campanulata :: Taiwan Flowering Cherry
## 493                                                      Ulmus procera :: English Elm
## 494                                    Acer palmatum 'Sango Kaku' :: Coral Bark Maple
## 495                       Acer rubrum 'Autumn Glory' :: Red Maple Tree 'Autumn Glory'
## 496                                 Ficus carica 'Black Mission' :: Black Mission Fig
## 497                                Juglans 'Paradox' :: Paradox Walnut Tree 'Paradox'
## 498                                        Liquidambar formosana :: Chinese Sweet Gum
## 499                          Liquidambar styraciflua 'Burgundy' :: Burgundy Sweet Gum
## 500                           Magnolia doltsopa 'Silvercloud' :: Silvercloud Magnolia
## 501                                                               Metrosideros spp ::
## 502                       Pyrus pyrifolia '20th Century' :: Asian Pear '20th Century'
## 503                               Robinia x ambigua 'Idahoensis' :: Idaho Pink Locust
## 504                          Zelkova serrata 'Village Green' :: Village Green Zelkova
## 505                                                     Acer campestre :: Hedge Maple
## 506                                   Acer platanoides 'Crimson King' :: Norway maple
## 507                                                  Acer platanoides :: Norway Maple
## 508                                                     Acer saccharum :: Sugar Maple
## 509                                                     Aesculus spp :: Horsechestnut
## 510                                                          Alnus rubra :: Red Alder
## 511                                                Araucaria bidwillii :: Bunya Bunya
## 512                                         Brahea brandegeei :: San Jose hesper palm
## 513                               Callistemon salignus :: White flowering bottlebrush
## 514                                                        Carya illinoensis :: Pecan
## 515                                             Castanea dentata :: American Chestnut
## 516                                              Catalpa speciosa :: Northern Catalpa
## 517                                               Cedrela fissilis :: Argentine cedar
## 518                                                    Cedrus libani :: Lebanon cedar
## 519                                       Cercocarpus betuloides :: Mountain mahogany
## 520                                   Crinodendron patagua :: Lily-of-the-Valley Tree
## 521                                                  Cupressus spp :: Cypress species
## 522                                                   Dypsis decaryi :: Triangle palm
## 523                                               Euphorbia ingens :: Candelabra tree
## 524                         Fraxinus velutina 'Modesto' :: Modesto Ash Tree 'Modesto'
## 525                                                            Geijera spp :: Geijera
## 526                            Juniperus scopulorum 'Pat :: Juniper Tree 'Pathfinder'
## 527                                         Lagerstroemia spp :: Crape myrtle species
## 528                             Lagerstroemia x 'Tuscarora' :: Tuscarora Crape Myrtle
## 529                                           Livistona chinensis :: Chinese fan palm
## 530                                                Macadamia tetraphylla :: Macadamia
## 531       Magnolia grandiflora 'Timeless Beauty' :: Timeless Beauty Southern Magnolia
## 532                                                         Mangifera indica :: Mango
## 533                                        Melaleuca leucadendron :: Weeping Tea Tree
## 534                                        Metrosideros robusta :: Northern Rata Tree
## 535                                                Moringa oleifera :: Drumstick tree
## 536                                               Phoenix rupicola :: Cliff date palm
## 537                                                   Pinus pinaster :: Maritime Pine
## 538                                               Pinus strobus :: Eastern white pine
## 539                                                    Pinus sylvestris :: Scots Pine
## 540                                           Populus deltoides :: Eastern cottonwood
## 541                                  Prunus domestica 'Green Gage' :: Green Gage Plum
## 542                              Prunus persica nectarina :: Flowering Nectarine Tree
## 543                                               Pseudopanax lessonii :: Five finger
## 544                                                Rhopalostylis sapida :: Nikau palm
## 545                                                    Rhus typhina :: Staghorn sumac
## 546                                      Sorbus aucuparia :: European Mountain Ash Tr
## 547                                            Stenocarpus sinuatus :: Firewheel tree
## 548                                                Taxodium distichum :: Bald Cypress
## 549                                          Torreya californica :: California nutmeg
## 550                                                        Ulmus glabra :: Scotch Elm
## 551                                                Wodyetia bifurcata :: Foxtail palm
## 552                            x Chiranthofremontia lenzii :: Hybrid Monkey Hand Tree
## 553                                                Yucca aloifolia :: Spanish bayonet
## 554                                                        Acer ginnela :: Amur Maple
## 555                                                     Acer paxii :: Evergreen Maple
## 556                                    Acer tegmentosum :: Manchurian snakebark maple
## 557                                             Acer x 'Autumn Blaze' :: Hybrid Maple
## 558                                          Cercidiphyllum japonicum :: Katsura tree
## 559                                                   Citrus x hystrix :: Kaffir lime
## 560                                Fagus sylvatica 'Red Obelisk' :: Red Obelisk Beech
## 561                                   Ficus carica 'Brown Turkey' :: Brown Turkey Fig
## 562                        Lagerstroemia indica 'Tuscarora' :: Tuscarora Crape Myrtle
## 563                Liquidambar styraciflua 'Slender Silhoutte' :: Upright Liquidambar
## 564                                            Malus 'Fuji' :: Fuji Apple Tree 'Fuji'
## 565                                     Myrica californica :: Pacific Wax Myrtle Tree
## 566                                     Persea americana 'Stewart' :: Stewart Avocado
## 567                                                    Pinus torreyana :: Torrey Pine
## 568                 Prunus sargentii 'Columnaris' :: Sargent Cherry Tree 'Columnaris'
## 569                                                Prunus sargentii :: Sargent Cherry
## 570                             Pyrus pyrifolia 'Sainseiki' :: Asian Pear 'Sainseiki'
## 571                           Ulmus parvifolia 'True Green' :: True Green Chinese Elm
##     ntotal ndate.na percent.missing
## 1    11629     1563      0.13440537
## 2    11557     9773      0.84563468
## 3     8744     6470      0.73993596
## 4     8581     4481      0.52220021
## 5     7197     3682      0.51160206
## 6     7122     5080      0.71328279
## 7     6716     4130      0.61494937
## 8     6285     3956      0.62943516
## 9     5702     2456      0.43072606
## 10    5624     4882      0.86806543
## 11    4025     2581      0.64124224
## 12    3956     3584      0.90596562
## 13    3899     2495      0.63990767
## 14    3694     2456      0.66486194
## 15    3575     3143      0.87916084
## 16    3266     2651      0.81169626
## 17    3212     1917      0.59682441
## 18    2969     1918      0.64600876
## 19    2696      948      0.35163205
## 20    2402     1120      0.46627810
## 21    2366     1900      0.80304311
## 22    2278     2138      0.93854258
## 23    2185     1715      0.78489703
## 24    1974     1017      0.51519757
## 25    1922     1862      0.96878252
## 26    1839     1618      0.87982599
## 27    1797      660      0.36727880
## 28    1795     1315      0.73259053
## 29    1736      790      0.45506912
## 30    1640     1341      0.81768293
## 31    1632     1360      0.83333333
## 32    1590     1347      0.84716981
## 33    1520     1127      0.74144737
## 34    1404     1347      0.95940171
## 35    1387     1207      0.87022350
## 36    1373      910      0.66278223
## 37    1170      603      0.51538462
## 38    1077      436      0.40482823
## 39    1059      771      0.72804533
## 40    1005      824      0.81990050
## 41     994      676      0.68008048
## 42     966      609      0.63043478
## 43     950      524      0.55157895
## 44     935      407      0.43529412
## 45     913      447      0.48959474
## 46     893      656      0.73460246
## 47     890      537      0.60337079
## 48     859      610      0.71012806
## 49     855      688      0.80467836
## 50     855      546      0.63859649
## 51     834      393      0.47122302
## 52     808      261      0.32301980
## 53     718      643      0.89554318
## 54     708      388      0.54802260
## 55     665      452      0.67969925
## 56     632      403      0.63765823
## 57     618      277      0.44822006
## 58     598      416      0.69565217
## 59     574      227      0.39547038
## 60     557      512      0.91921005
## 61     551      412      0.74773140
## 62     548      300      0.54744526
## 63     504      424      0.84126984
## 64     497      487      0.97987928
## 65     492      310      0.63008130
## 66     489      476      0.97341513
## 67     487      274      0.56262834
## 68     438      139      0.31735160
## 69     429      404      0.94172494
## 70     428      420      0.98130841
## 71     428      235      0.54906542
## 72     421      244      0.57957245
## 73     412      342      0.83009709
## 74     406      243      0.59852217
## 75     400       43      0.10750000
## 76     395      202      0.51139241
## 77     393      315      0.80152672
## 78     390      333      0.85384615
## 79     380       49      0.12894737
## 80     379      347      0.91556728
## 81     368      326      0.88586957
## 82     357      168      0.47058824
## 83     350      250      0.71428571
## 84     341      301      0.88269795
## 85     332      279      0.84036145
## 86     332      247      0.74397590
## 87     329      322      0.97872340
## 88     326      136      0.41717791
## 89     320      245      0.76562500
## 90     314      159      0.50636943
## 91     306      284      0.92810458
## 92     302      171      0.56622517
## 93     296      110      0.37162162
## 94     286      270      0.94405594
## 95     276      191      0.69202899
## 96     268      168      0.62686567
## 97     267       81      0.30337079
## 98     260      167      0.64230769
## 99     258       63      0.24418605
## 100    257      241      0.93774319
## 101    251      149      0.59362550
## 102    249       71      0.28514056
## 103    247      132      0.53441296
## 104    242      113      0.46694215
## 105    226      159      0.70353982
## 106    226      111      0.49115044
## 107    222      122      0.54954955
## 108    218      192      0.88073394
## 109    210      170      0.80952381
## 110    201      122      0.60696517
## 111    200      133      0.66500000
## 112    194      186      0.95876289
## 113    194      183      0.94329897
## 114    183      167      0.91256831
## 115    180      129      0.71666667
## 116    176      153      0.86931818
## 117    171      138      0.80701754
## 118    168      149      0.88690476
## 119    161      127      0.78881988
## 120    160      157      0.98125000
## 121    160      102      0.63750000
## 122    159        5      0.03144654
## 123    155      118      0.76129032
## 124    154      146      0.94805195
## 125    154      108      0.70129870
## 126    154       28      0.18181818
## 127    153      109      0.71241830
## 128    151      147      0.97350993
## 129    147      135      0.91836735
## 130    147       49      0.33333333
## 131    146      141      0.96575342
## 132    144       42      0.29166667
## 133    143      133      0.93006993
## 134    143       77      0.53846154
## 135    142      111      0.78169014
## 136    141      130      0.92198582
## 137    140        8      0.05714286
## 138    139       91      0.65467626
## 139    136       14      0.10294118
## 140    134      110      0.82089552
## 141    131        2      0.01526718
## 142    130       18      0.13846154
## 143    126        7      0.05555556
## 144    121      116      0.95867769
## 145    118       NA              NA
## 146    116       91      0.78448276
## 147    116       71      0.61206897
## 148    108       99      0.91666667
## 149    107      106      0.99065421
## 150    106       NA              NA
## 151    105      100      0.95238095
## 152    103       92      0.89320388
## 153    103       57      0.55339806
## 154    100      100      1.00000000
## 155    100       73      0.73000000
## 156     99       81      0.81818182
## 157     99       66      0.66666667
## 158     98       72      0.73469388
## 159     97       94      0.96907216
## 160     97       77      0.79381443
## 161     97       63      0.64948454
## 162     94       77      0.81914894
## 163     92       91      0.98913043
## 164     92       36      0.39130435
## 165     91       89      0.97802198
## 166     91       84      0.92307692
## 167     91       58      0.63736264
## 168     90       25      0.27777778
## 169     89       55      0.61797753
## 170     87       84      0.96551724
## 171     86       36      0.41860465
## 172     85       84      0.98823529
## 173     84       51      0.60714286
## 174     82       58      0.70731707
## 175     81       78      0.96296296
## 176     81       36      0.44444444
## 177     81       32      0.39506173
## 178     81        9      0.11111111
## 179     80       72      0.90000000
## 180     80       51      0.63750000
## 181     78       63      0.80769231
## 182     76       69      0.90789474
## 183     76       61      0.80263158
## 184     75       58      0.77333333
## 185     74       67      0.90540541
## 186     74       61      0.82432432
## 187     74       51      0.68918919
## 188     72       58      0.80555556
## 189     67       65      0.97014925
## 190     66       59      0.89393939
## 191     64       37      0.57812500
## 192     61       58      0.95081967
## 193     61       57      0.93442623
## 194     60       58      0.96666667
## 195     60       57      0.95000000
## 196     59       39      0.66101695
## 197     58       54      0.93103448
## 198     58       53      0.91379310
## 199     57       54      0.94736842
## 200     57       54      0.94736842
## 201     57       51      0.89473684
## 202     57       37      0.64912281
## 203     57        5      0.08771930
## 204     55       42      0.76363636
## 205     54       53      0.98148148
## 206     54       36      0.66666667
## 207     53       50      0.94339623
## 208     53       36      0.67924528
## 209     52       37      0.71153846
## 210     51       NA              NA
## 211     50       44      0.88000000
## 212     49       12      0.24489796
## 213     47       39      0.82978723
## 214     47        7      0.14893617
## 215     46       27      0.58695652
## 216     45       44      0.97777778
## 217     45       19      0.42222222
## 218     43       14      0.32558140
## 219     42       37      0.88095238
## 220     42        3      0.07142857
## 221     42        2      0.04761905
## 222     41       29      0.70731707
## 223     40       37      0.92500000
## 224     40       12      0.30000000
## 225     40       NA              NA
## 226     39       37      0.94871795
## 227     38       29      0.76315789
## 228     38       13      0.34210526
## 229     38        2      0.05263158
## 230     37       35      0.94594595
## 231     37       33      0.89189189
## 232     36       20      0.55555556
## 233     34       34      1.00000000
## 234     34       32      0.94117647
## 235     34       29      0.85294118
## 236     33       30      0.90909091
## 237     33       20      0.60606061
## 238     32       23      0.71875000
## 239     31       31      1.00000000
## 240     31       28      0.90322581
## 241     31       26      0.83870968
## 242     30       27      0.90000000
## 243     30       24      0.80000000
## 244     29       26      0.89655172
## 245     29       26      0.89655172
## 246     29       26      0.89655172
## 247     29       22      0.75862069
## 248     28       20      0.71428571
## 249     27       26      0.96296296
## 250     27       23      0.85185185
## 251     26       26      1.00000000
## 252     26       25      0.96153846
## 253     26        2      0.07692308
## 254     25       17      0.68000000
## 255     24        9      0.37500000
## 256     24        8      0.33333333
## 257     24        3      0.12500000
## 258     23       22      0.95652174
## 259     23       22      0.95652174
## 260     23       21      0.91304348
## 261     23       21      0.91304348
## 262     23       20      0.86956522
## 263     23       19      0.82608696
## 264     23       18      0.78260870
## 265     23        8      0.34782609
## 266     22       20      0.90909091
## 267     22       20      0.90909091
## 268     22       13      0.59090909
## 269     22       10      0.45454545
## 270     21       21      1.00000000
## 271     21       15      0.71428571
## 272     20       18      0.90000000
## 273     20       17      0.85000000
## 274     19       19      1.00000000
## 275     19       18      0.94736842
## 276     19       18      0.94736842
## 277     19       15      0.78947368
## 278     19       13      0.68421053
## 279     19        9      0.47368421
## 280     19        8      0.42105263
## 281     19        1      0.05263158
## 282     18       17      0.94444444
## 283     18       17      0.94444444
## 284     18        7      0.38888889
## 285     17       16      0.94117647
## 286     17       15      0.88235294
## 287     17       14      0.82352941
## 288     17       13      0.76470588
## 289     17       11      0.64705882
## 290     17        7      0.41176471
## 291     16       16      1.00000000
## 292     16       16      1.00000000
## 293     16       14      0.87500000
## 294     16       14      0.87500000
## 295     16       11      0.68750000
## 296     16       10      0.62500000
## 297     15       15      1.00000000
## 298     15       14      0.93333333
## 299     15       14      0.93333333
## 300     15       14      0.93333333
## 301     15        3      0.20000000
## 302     14       11      0.78571429
## 303     14       10      0.71428571
## 304     14        9      0.64285714
## 305     14        8      0.57142857
## 306     14        4      0.28571429
## 307     14        2      0.14285714
## 308     14        1      0.07142857
## 309     13       13      1.00000000
## 310     13       13      1.00000000
## 311     13       13      1.00000000
## 312     13       13      1.00000000
## 313     13       12      0.92307692
## 314     13       10      0.76923077
## 315     13       10      0.76923077
## 316     13        6      0.46153846
## 317     13        5      0.38461538
## 318     13       NA              NA
## 319     12       12      1.00000000
## 320     12       12      1.00000000
## 321     12       12      1.00000000
## 322     12       12      1.00000000
## 323     12       12      1.00000000
## 324     12       11      0.91666667
## 325     12       11      0.91666667
## 326     12       10      0.83333333
## 327     12       10      0.83333333
## 328     12        8      0.66666667
## 329     11       11      1.00000000
## 330     11       11      1.00000000
## 331     11       10      0.90909091
## 332     11        9      0.81818182
## 333     11        7      0.63636364
## 334     10        9      0.90000000
## 335     10        9      0.90000000
## 336     10        9      0.90000000
## 337     10        8      0.80000000
## 338     10        5      0.50000000
## 339     10       NA              NA
## 340     10       NA              NA
## 341      9        9      1.00000000
## 342      9        9      1.00000000
## 343      9        8      0.88888889
## 344      9        7      0.77777778
## 345      9        7      0.77777778
## 346      9        7      0.77777778
## 347      9        4      0.44444444
## 348      9        4      0.44444444
## 349      9        3      0.33333333
## 350      9        1      0.11111111
## 351      9        1      0.11111111
## 352      9       NA              NA
## 353      9       NA              NA
## 354      8        8      1.00000000
## 355      8        8      1.00000000
## 356      8        8      1.00000000
## 357      8        6      0.75000000
## 358      8        3      0.37500000
## 359      8        1      0.12500000
## 360      8       NA              NA
## 361      8       NA              NA
## 362      8       NA              NA
## 363      7        7      1.00000000
## 364      7        7      1.00000000
## 365      7        7      1.00000000
## 366      7        6      0.85714286
## 367      7        5      0.71428571
## 368      7        5      0.71428571
## 369      7        2      0.28571429
## 370      7        1      0.14285714
## 371      7        1      0.14285714
## 372      7       NA              NA
## 373      7       NA              NA
## 374      6        6      1.00000000
## 375      6        6      1.00000000
## 376      6        6      1.00000000
## 377      6        6      1.00000000
## 378      6        6      1.00000000
## 379      6        5      0.83333333
## 380      6        5      0.83333333
## 381      6        5      0.83333333
## 382      6        5      0.83333333
## 383      6        5      0.83333333
## 384      6        4      0.66666667
## 385      6        4      0.66666667
## 386      6        4      0.66666667
## 387      6        3      0.50000000
## 388      6       NA              NA
## 389      6       NA              NA
## 390      5        5      1.00000000
## 391      5        5      1.00000000
## 392      5        5      1.00000000
## 393      5        5      1.00000000
## 394      5        5      1.00000000
## 395      5        5      1.00000000
## 396      5        5      1.00000000
## 397      5        4      0.80000000
## 398      5        4      0.80000000
## 399      5        4      0.80000000
## 400      5        4      0.80000000
## 401      5        4      0.80000000
## 402      5        3      0.60000000
## 403      5        3      0.60000000
## 404      5        2      0.40000000
## 405      5        2      0.40000000
## 406      5        1      0.20000000
## 407      4        4      1.00000000
## 408      4        4      1.00000000
## 409      4        4      1.00000000
## 410      4        4      1.00000000
## 411      4        4      1.00000000
## 412      4        4      1.00000000
## 413      4        4      1.00000000
## 414      4        4      1.00000000
## 415      4        4      1.00000000
## 416      4        4      1.00000000
## 417      4        4      1.00000000
## 418      4        4      1.00000000
## 419      4        4      1.00000000
## 420      4        3      0.75000000
## 421      4        3      0.75000000
## 422      4        3      0.75000000
## 423      4        3      0.75000000
## 424      4        3      0.75000000
## 425      4        3      0.75000000
## 426      4        3      0.75000000
## 427      4        3      0.75000000
## 428      4        2      0.50000000
## 429      4        2      0.50000000
## 430      4        1      0.25000000
## 431      4        1      0.25000000
## 432      4       NA              NA
## 433      4       NA              NA
## 434      4       NA              NA
## 435      4       NA              NA
## 436      3        3      1.00000000
## 437      3        3      1.00000000
## 438      3        3      1.00000000
## 439      3        3      1.00000000
## 440      3        3      1.00000000
## 441      3        3      1.00000000
## 442      3        3      1.00000000
## 443      3        3      1.00000000
## 444      3        3      1.00000000
## 445      3        3      1.00000000
## 446      3        3      1.00000000
## 447      3        3      1.00000000
## 448      3        2      0.66666667
## 449      3        2      0.66666667
## 450      3        1      0.33333333
## 451      3        1      0.33333333
## 452      3        1      0.33333333
## 453      3        1      0.33333333
## 454      3        1      0.33333333
## 455      3        1      0.33333333
## 456      3       NA              NA
## 457      3       NA              NA
## 458      3       NA              NA
## 459      3       NA              NA
## 460      3       NA              NA
## 461      2        2      1.00000000
## 462      2        2      1.00000000
## 463      2        2      1.00000000
## 464      2        2      1.00000000
## 465      2        2      1.00000000
## 466      2        2      1.00000000
## 467      2        2      1.00000000
## 468      2        2      1.00000000
## 469      2        2      1.00000000
## 470      2        2      1.00000000
## 471      2        2      1.00000000
## 472      2        2      1.00000000
## 473      2        2      1.00000000
## 474      2        2      1.00000000
## 475      2        2      1.00000000
## 476      2        2      1.00000000
## 477      2        2      1.00000000
## 478      2        2      1.00000000
## 479      2        2      1.00000000
## 480      2        2      1.00000000
## 481      2        2      1.00000000
## 482      2        2      1.00000000
## 483      2        2      1.00000000
## 484      2        2      1.00000000
## 485      2        2      1.00000000
## 486      2        2      1.00000000
## 487      2        2      1.00000000
## 488      2        1      0.50000000
## 489      2        1      0.50000000
## 490      2        1      0.50000000
## 491      2        1      0.50000000
## 492      2        1      0.50000000
## 493      2        1      0.50000000
## 494      2       NA              NA
## 495      2       NA              NA
## 496      2       NA              NA
## 497      2       NA              NA
## 498      2       NA              NA
## 499      2       NA              NA
## 500      2       NA              NA
## 501      2       NA              NA
## 502      2       NA              NA
## 503      2       NA              NA
## 504      2       NA              NA
## 505      1        1      1.00000000
## 506      1        1      1.00000000
## 507      1        1      1.00000000
## 508      1        1      1.00000000
## 509      1        1      1.00000000
## 510      1        1      1.00000000
## 511      1        1      1.00000000
## 512      1        1      1.00000000
## 513      1        1      1.00000000
## 514      1        1      1.00000000
## 515      1        1      1.00000000
## 516      1        1      1.00000000
## 517      1        1      1.00000000
## 518      1        1      1.00000000
## 519      1        1      1.00000000
## 520      1        1      1.00000000
## 521      1        1      1.00000000
## 522      1        1      1.00000000
## 523      1        1      1.00000000
## 524      1        1      1.00000000
## 525      1        1      1.00000000
## 526      1        1      1.00000000
## 527      1        1      1.00000000
## 528      1        1      1.00000000
## 529      1        1      1.00000000
## 530      1        1      1.00000000
## 531      1        1      1.00000000
## 532      1        1      1.00000000
## 533      1        1      1.00000000
## 534      1        1      1.00000000
## 535      1        1      1.00000000
## 536      1        1      1.00000000
## 537      1        1      1.00000000
## 538      1        1      1.00000000
## 539      1        1      1.00000000
## 540      1        1      1.00000000
## 541      1        1      1.00000000
## 542      1        1      1.00000000
## 543      1        1      1.00000000
## 544      1        1      1.00000000
## 545      1        1      1.00000000
## 546      1        1      1.00000000
## 547      1        1      1.00000000
## 548      1        1      1.00000000
## 549      1        1      1.00000000
## 550      1        1      1.00000000
## 551      1        1      1.00000000
## 552      1        1      1.00000000
## 553      1        1      1.00000000
## 554      1       NA              NA
## 555      1       NA              NA
## 556      1       NA              NA
## 557      1       NA              NA
## 558      1       NA              NA
## 559      1       NA              NA
## 560      1       NA              NA
## 561      1       NA              NA
## 562      1       NA              NA
## 563      1       NA              NA
## 564      1       NA              NA
## 565      1       NA              NA
## 566      1       NA              NA
## 567      1       NA              NA
## 568      1       NA              NA
## 569      1       NA              NA
## 570      1       NA              NA
## 571      1       NA              NA

We look at the total number of observations we would lose if we drop species where missing 100% of date information. And the number is very small relative to total number of observations (n = 192987)

df_trees_merge %>% filter(percent.missing==1) %>% select(ntotal) %>%
  sum()
## [1] 731
  #arrange(desc(percent.missing), desc(ntotal))

How the percentage of missing date values per species is distributed. All species that have 100% of date data missing have a very low number of observations (n <=100).

df_trees_merge %>% 
  ggplot(aes(percent.missing))+geom_histogram() +scale_x_continuous(breaks=seq(0,1, .10))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 54 rows containing non-finite values (stat_bin).

Therefore, we now filter the cases based on this 100 ntotal threshold to get a cleaner histogram.

df_trees_merge %>% filter(ntotal>100) %>%
  ggplot(aes(percent.missing))+geom_histogram() +scale_x_continuous(breaks=seq(0,1, .10))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 2 rows containing non-finite values (stat_bin).

Exploratory Analysis

Checking year of plantation range. most of the trees (50%) were planted between 2001 and 2020. However, it is likely that many of the older trees simply were not recorded so they either dont appear in our data or have a missing date value.

df_trees %>%
  select(year)%>%
  quantile(na.rm = TRUE)
##   0%  25%  50%  75% 100% 
## 1955 1995 2001 2008 2020

Create a new column that shows age using the year column to calculate it. Use the more modern approach mutate(). Then use age column to get an overview of the distribution of tree ages via a histogram.

df_trees <- df_trees %>% 
  mutate(age = year(Sys.Date())-year)


hist(df_trees$age, main = 'Tree Age Distribution', xlab = 'Age', col = 'royalblue2') # using base r

Count the species

df_trees %>%
  count(species_lat) %>%
  arrange(desc(n)) %>%
  top_n(n = 20)
## Selecting by n
##                             species_lat     n
## 1                              Tree(s)  11629
## 2                 Platanus x hispanica  11557
## 3                 Metrosideros excelsa   8744
## 4                Lophostemon confertus   8581
## 5                Tristaniopsis laurina   7197
## 6                Pittosporum undulatum   7122
## 7                    Prunus cerasifera   6716
## 8                 Magnolia grandiflora   6285
## 9                     Arbutus 'Marina'   5702
## 10 Ficus microcarpa nitida 'Green Gem'   5624
## 11          Prunus serrulata 'Kwanzan'   4025
## 12                  Acacia melanoxylon   3956
## 13                     Maytenus boaria   3899
## 14                       Olea europaea   3694
## 15                  Corymbia ficifolia   3575
## 16                Callistemon citrinus   3266
## 17                       Ginkgo biloba   3212
## 18                    Pyrus calleryana   2969
## 19                    Prunus serrulata   2696
## 20                  Eriobotrya deflexa   2402

Show number of distinct species in a street

df_trees %>%
  group_by(address) %>%
  summarize(n = n_distinct(species_lat)) %>%
  arrange(desc(n))
## # A tibble: 85,910 x 2
##    address                     n
##    <fct>                   <int>
##  1 <NA>                       43
##  2 900x Carolina St           31
##  3 1201 San Jose Ave          30
##  4 1301 Minnesota St          28
##  5 310 Liberty St             26
##  6 1000 San Jose Ave          24
##  7 1100 San Jose Ave          24
##  8 2200 Sunset Blvd           20
##  9 2600 Sunset Blvd           20
## 10 700 Junipero Serra Blvd    20
## # ... with 85,900 more rows

Analysis 1: evolution of planted species over time

To do this specific analysis we drop the trees, which have missing date data for obvious reasons. Based on our missing date data analysis in the data cleaning section, we are confident the data does not display any obvious signs of MNAR.

Selected related columns

df_trees_hasdate <- df_trees %>% 
  filter(!is.na(date)) %>% 
  select(c("tree_id", "species_lat", "year"))

str(df_trees_hasdate)
## 'data.frame':    68377 obs. of  3 variables:
##  $ tree_id    : int  53719 30313 30312 30314 30315 30316 48435 30319 30318 30320 ...
##  $ species_lat: chr  "Tree(s) " "Tree(s) " "Tree(s) " "Pittosporum undulatum " ...
##  $ year       : num  1955 1955 1955 1955 1955 ...
df_trees_hasdate$species_lat <- as.factor(df_trees_hasdate$species_lat)
str(df_trees_hasdate)
## 'data.frame':    68377 obs. of  3 variables:
##  $ tree_id    : int  53719 30313 30312 30314 30315 30316 48435 30319 30318 30320 ...
##  $ species_lat: Factor w/ 427 levels "","Acacia baileyana ",..: 405 405 405 287 7 7 405 221 221 99 ...
##  $ year       : num  1955 1955 1955 1955 1955 ...

To make the number of species more manageable, we group them by family names (i.e Acacia, Magnolia)

unique(df_trees_hasdate[grep(df_trees_hasdate$species_lat, pattern = "^Acacia", ignore.case = TRUE), 'species_lat'])
## [1] Acacia melanoxylon           Acacia longifolia           
## [3] Acacia stenophylla           Acacia baileyana            
## [5] Acacia baileyana 'Purpurea'  Acacia cognata              
## [7] Acacia spp                   Acacia decurrens            
## 427 Levels:  Acacia baileyana  Acacia baileyana 'Purpurea'  ... Zelkova serrata 'Village Green'
unique(df_trees_hasdate[grep(df_trees_hasdate$species_lat, pattern = "^Magnolia", ignore.case = TRUE), 'species_lat'])
##  [1] Magnolia grandiflora                   
##  [2] Magnolia spp                           
##  [3] Magnolia grandiflora 'Little Gem'      
##  [4] Magnolia champaca                      
##  [5] Magnolia doltsopa                      
##  [6] Magnolia grandiflora 'Samuel Sommer'   
##  [7] Magnolia grandiflora 'Saint Mary'      
##  [8] Magnolia grandiflora 'Russet'          
##  [9] Magnolia x soulangiana                 
## [10] Magnolia x foggii 'Jack Fogg'          
## [11] Magnolia grandiflora 'Majestic Beauty' 
## [12] Magnolia grandiflora 'D.D. Blanchard'  
## [13] Magnolia sargentiana 'Robusta'         
## [14] Magnolia x alba                        
## [15] Magnolia doltsopa 'Silvercloud'        
## 427 Levels:  Acacia baileyana  Acacia baileyana 'Purpurea'  ... Zelkova serrata 'Village Green'

It seems that specific species can be grouped together with a general name. Since the general name is the first word of the species name, we will separate the species name into its words and then use the first word as the species general name.

Separate the species_lat column into first and second part

df_trees_hasdate <- df_trees_hasdate %>% 
  separate(species_lat, sep = " ", remove = FALSE, into = c('species_first', 'species_second', 'species_third'))
## Warning: Expected 3 pieces. Additional pieces discarded in 10662 rows [23, 25,
## 87, 88, 89, 91, 92, 93, 94, 97, 104, 105, 106, 111, 113, 119, 120, 121, 129,
## 162, ...].
## Warning: Expected 3 pieces. Missing pieces filled with `NA` in 10324 rows [1, 2,
## 3, 7, 17, 20, 30, 31, 33, 36, 38, 39, 41, 42, 43, 45, 46, 47, 48, 50, ...].

The code below shows that the number of unique species after recategorizing species_lat is 158.

length(unique(df_trees_hasdate$species_first))
## [1] 158

Create a count column to save number of planted trees by species, per year.

df_trees_hasdate_tidy <- df_trees_hasdate %>%
  group_by(year) %>%
  count(species_first) %>%
  arrange(year, desc(n)) 

As a bit of side note we look at the total number of planted trees per year regardless of species to get a sense of overall tree planting

df_trees_hasdate_tidy %>%
  select(c('year', 'n')) %>%
  aggregate(by = list(df_trees_hasdate_tidy$year), FUN='sum') %>%
  ggplot(aes(x = Group.1, y = n)) + 
  geom_line() + 
  labs(title = 'Total Number of Planted Trees per Year', 
       x = 'Year', y = 'Total number of planted trees') +
  theme_minimal()

Animated Graph

In this step, We’re going to filter our data set to retain only the top 10 planted species for every given year to keep the visuals understandable. Also we drop the species labelled Tree(s) as this obviously tells us nothing about the species.

df_trees_hasdate_formated <- df_trees_hasdate_tidy %>% subset(species_first != 'Tree(s)') %>% 
  group_by(year) %>%
  mutate(rank = rank(-n)) %>%
  filter(rank <=10) 

In this step, we will create individual static graphs for each year.

staticplot = ggplot(df_trees_hasdate_formated, aes(rank, group = species_first, 
                fill = as.factor(species_first), color = as.factor(species_first))) +
  geom_tile(aes(y = n/2,
                height = n,
                width = 0.9), alpha = 0.8, color = NA) +
  geom_text(aes(y = 0, label = paste(species_first, " ")), vjust = 0.2, hjust = 1) +
  geom_text(aes(y=n, label = n, hjust=0)) +
  coord_flip(clip = "off", expand = FALSE) +
  scale_y_continuous(labels = scales::comma) +
  scale_x_reverse() +
  guides(color = FALSE, fill = FALSE) +
  theme(axis.line=element_blank(),
        axis.text.x=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks=element_blank(),
        axis.title.x=element_blank(),
         axis.title.y=element_blank(),
        legend.position="none",
        panel.background=element_blank(),
        panel.border=element_blank(),
        panel.grid.major=element_blank(),
        panel.grid.minor=element_blank(),
        panel.grid.major.x = element_line( size=.1, color="grey" ),
        panel.grid.minor.x = element_line( size=.1, color="grey" ),
        plot.title=element_text(size=25, hjust=0.5, face="bold", colour="grey", vjust=-1),
        plot.subtitle=element_text(size=18, hjust=0.5, face="italic", color="grey"),
        plot.caption =element_text(size=8, hjust=0.5, face="italic", color="grey"),
        plot.background=element_blank(),
       plot.margin = margin(2,2, 2, 4, "cm"))
anim = staticplot + transition_states(year, transition_length = 4, state_length = 1) +
  view_follow(fixed_x = TRUE)  +
  labs(title = 'Total Number of Planted Trees per Year: {closest_state}',  
       subtitle  =  "Top 10 Species")

For gif

animate(anim, 200, fps = 2,  width = 1200, height = 1000, 
        renderer = gifski_renderer("gganim.gif"))
## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

For Video

# For MP4
for_mp4 <- animate(anim, 200, fps = 5,  width = 1200, height = 1000, renderer = av_renderer()) 
## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?

## Warning: Position guide is perpendicular to the intended axis. Did you mean to
## specify a different guide `position`?
anim_save("animation.mp4", animation = for_mp4 )

Alternative: cumulative total of top 5 species over time

find out which are the top 5 most planted species over entire time period. ‘Trees’ category will be omitted as it tells us nothing about species

df_agg <- aggregate(df_trees_hasdate_tidy$n, by=list(df_trees_hasdate_tidy$species_first), FUN='sum')
df_agg %>%
  arrange(desc(x)) %>%
  top_n(n=6)
## Selecting by x
##         Group.1     x
## 1       Tree(s) 10066
## 2        Prunus  6393
## 3 Tristaniopsis  4652
## 4   Lophostemon  4100
## 5      Magnolia  3773
## 6       Arbutus  3475

create df to be used for cumulative summation

df_top5 <- df_trees_hasdate_tidy %>%
  filter(species_first == 'Prunus' | species_first == 'Tristaniopsis' | species_first == 'Lophostemon' | species_first == 'Magnolia' | species_first =='Arbutus')

Calculate the cumulative summation for each species.

df_top5_cumsum <- df_top5 %>% 
  group_by(species_first) %>% 
  mutate(csum = cumsum(n))
#install.packages('transformr')
library('transformr')

Save the data type of year column as Date

df_top5_cumsum$year <- lubridate::ymd(df_top5_cumsum$year, truncated = 2L)

Create the static plot

species_cumsum <- ggplot(df_top5_cumsum, aes(x=year,y=csum, group=species_first, col=factor(species_first))) + geom_line() + scale_color_manual(values = c('#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00')) + theme_minimal() 

Create the animated plot with transition

anim2 <- species_cumsum + transition_reveal(year) + view_follow(fixed_x = TRUE)  +
  labs(title = 'Cumulative Total of Top 5 Species over Time', x = 'Year', y = 'Cumulative Sum')

Animated graph (gif version):

animate(anim2, 200, fps = 3,  width = 1200, height = 1000, 
        renderer = gifski_renderer("gganim2.gif"))

#Analysis 2:

map of recommended species per (https://sfenvironment.org/sites/default/files/fliers/files/sf_tree_guide.pdf) :

recommended_sp <- c(' Japanese Blueberry Tree', ' Flaxleaf Paperbark', ' Red Flowering Gum', ' Flowering Cherry', 
                    ' Little Gem Magnolia', ' Southern Magnolia', ' Weeping Bottlebrush', ' Hybrid Strawberry Tree', 
                    ' Primrose Tree', ' Brisbane Box', ' Mediterranean Fan Palm', ' Fruitless Olive', ' Chilean Soapbark', 
                    " Small-leaf Tristania 'Elegant'", ' Chinese Pistache', ' Trident Maple', ' Chinese Elm', ' Cork Oak', 
                    ' Ginkgo: Autumn Gold', ' Fairmont Ginkgo', ' Ginkgo: Saratoga', ' Autumn Sentinel Ginkgo'
                    )
unique(df_trees[grep(df_trees$species_nor, pattern = "Ginkgo", ignore.case = TRUE), 'species'])
## [1] Ginkgo biloba 'Autumn Gold' :: Ginkgo: Autumn Gold       
## [2] Ginkgo biloba 'Fairmont' :: Fairmont Ginkgo              
## [3] Ginkgo biloba 'Saratoga' :: Ginkgo: Saratoga             
## [4] Ginkgo biloba 'Autumn Sentinel' :: Autumn Sentinel Ginkgo
## 571 Levels: :: ... Ziziphus jujuba :: Jujube
df_trees$species_nor <- as.factor(df_trees$species_nor)
df_trees_filtered <- df_trees %>% 
  filter(species_nor %in% recommended_sp)
unique(df_trees_filtered$species_nor)
##  [1]  Southern Magnolia               Red Flowering Gum             
##  [3]  Hybrid Strawberry Tree          Chinese Elm                   
##  [5]  Brisbane Box                    Weeping Bottlebrush           
##  [7]  Little Gem Magnolia             Small-leaf Tristania 'Elegant'
##  [9]  Chinese Pistache                Fruitless Olive               
## [11]  Japanese Blueberry Tree         Trident Maple                 
## [13]  Flaxleaf Paperbark              Primrose Tree                 
## [15]  Ginkgo: Autumn Gold             Chilean Soapbark              
## [17]  Cork Oak                        Mediterranean Fan Palm        
## [19]  Fairmont Ginkgo                 Ginkgo: Saratoga              
## [21]  Autumn Sentinel Ginkgo          Flowering Cherry              
## 551 Levels:   'Akebono' Cherry  Acacia Spp ...  Yucca

Get the coordinates of the whole dataset

df_trees_filtered %>% 
  summarise(max_lon = max(longitude,  na.rm=TRUE), min_lon = min(longitude,  na.rm=TRUE),
            max_lat = max(latitude,  na.rm=TRUE), min_lat = min(latitude,  na.rm=TRUE))
##     max_lon   min_lon  max_lat  min_lat
## 1 -122.3692 -138.2839 47.27022 37.70793
register_google('AIzaSyB2pTXikWRKM3XgN4WC-p-Fu2mOs8fZK88')
san_francisco = c(left=-122.7, bottom = 37.7, right = -122.3, top = 37.85)
smap <- get_map(san_francisco, maptype = 'hybrid') %>% #get_stamenmap(san_francisco, maptype = 'watercolor')
  ggmap()
## Source : http://tile.stamen.com/terrain/12/651/1582.png
## Source : http://tile.stamen.com/terrain/12/652/1582.png
## Source : http://tile.stamen.com/terrain/12/653/1582.png
## Source : http://tile.stamen.com/terrain/12/654/1582.png
## Source : http://tile.stamen.com/terrain/12/655/1582.png
## Source : http://tile.stamen.com/terrain/12/656/1582.png
## Source : http://tile.stamen.com/terrain/12/651/1583.png
## Source : http://tile.stamen.com/terrain/12/652/1583.png
## Source : http://tile.stamen.com/terrain/12/653/1583.png
## Source : http://tile.stamen.com/terrain/12/654/1583.png
## Source : http://tile.stamen.com/terrain/12/655/1583.png
## Source : http://tile.stamen.com/terrain/12/656/1583.png
## Source : http://tile.stamen.com/terrain/12/651/1584.png
## Source : http://tile.stamen.com/terrain/12/652/1584.png
## Source : http://tile.stamen.com/terrain/12/653/1584.png
## Source : http://tile.stamen.com/terrain/12/654/1584.png
## Source : http://tile.stamen.com/terrain/12/655/1584.png
## Source : http://tile.stamen.com/terrain/12/656/1584.png
smap + geom_point(data = df_trees_filtered, aes(x=longitude, y = latitude, col = species_nor)) #+ scale_color_manual(values = c('#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00'))
## Warning: Removed 401 rows containing missing values (geom_point).

Create map with leaflet() package

## for all species

## will be added a color for each species. 

#map center
mlong = -122.4446
mlat  = 37.72

pal <- colorFactor('viridis', domain = recommended_sp)

leaflet(data = df_trees_filtered, 
                width = '100%', 
                height = 800,
                options = leafletOptions(minZoom = 9, maxZoom = 18)) %>% 
        addTiles() %>%
        setView(lng = mlong, lat = mlat, zoom = 12) %>%
        addCircleMarkers(lng = df_trees_filtered$longitude, 
                         lat = df_trees_filtered$latitude,
                         color = ~pal(df_trees_filtered$species_nor),
                         popup = df_trees_filtered$species_nor,
                         label = df_trees_filtered$species_nor, 
                         radius = 4) %>%
      addLayersControl(overlayGroups = df_trees_filtered$species_nor) ## add layers control
## Warning in validateCoords(lng, lat, funcName): Data contains 319 rows with
## either missing or invalid lat/lon values and will be ignored

but map is too chaotic give large number of species…sooo Shiny to the rescue:

Create a shiny app version of the map above, with a drop down menu to look at each species at a time.

#map center
mlong = -122.4446
mlat  = 37.72

pal <- colorFactor('Paired', domain = recommended_sp, reverse = TRUE)

shinyApp(
  
  # Define the UI
  ui = fluidPage(
      
    # App title
    titlePanel("Recommended Tree Species of San Francisco"),
               
    #tabPanel(a(href='https://sfenvironment.org/sites/default/files/fliers/files/sf_tree_guide.pdf', 'Source')),
      
    # Sidebar layout with input and output definitions
    sidebarLayout(
        
      # Sidebar panel for inputs 
      sidebarPanel(
          
        # First input: Type of data
        
        checkboxGroupInput(inputId = "species", #name of the input, widget
                      label = "Choose a species:",
                      choices = c('All Species',  ' Japanese Blueberry Tree', ' Flaxleaf Paperbark', ' Red Flowering Gum', 
                                  ' Flowering Cherry', ' Little Gem Magnolia', ' Southern Magnolia', ' Weeping Bottlebrush', 
                                  ' Hybrid Strawberry Tree', ' Primrose Tree', ' Brisbane Box', ' Mediterranean Fan Palm', 
                                  ' Fruitless Olive', ' Chilean Soapbark', " Small-leaf Tristania 'Elegant'", ' Chinese Pistache', 
                                  ' Trident Maple', ' Chinese Elm', ' Cork Oak', ' Ginkgo: Autumn Gold', ' Fairmont Ginkgo', 
                                  ' Ginkgo: Saratoga', ' Autumn Sentinel Ginkgo'
                    ), 
                      selected = ' Japanese Blueberry Tree'
        )),
        
      # Main panel for displaying outputs
      mainPanel(
          
        # Hide errors
        tags$style(type = "text/css",
                     ".shiny-output-error { visibility: hidden; }",
                     ".shiny-output-error:before { visibility: hidden; }"),
          
        # Output: interactive world map
        leafletOutput("map", height = 800)
          
        )
      )
    ),
    
  # Define the server
  server = function(input, output) {
    
    filteredData <- reactive({
      if (input$species == "All Species") {
        df_trees_filtered
      } else {
        filter(df_trees_filtered, species_nor == input$species)
      }
    })
      
    output$map <- renderLeaflet({
          
        leaflet(filteredData(), 
                width = '100%', 
                options = leafletOptions(minZoom = 9, maxZoom = 18)) %>% 
        addTiles() %>%
        setView(lng = mlong, lat = mlat, zoom = 12) %>%
        addCircleMarkers(lng = filteredData()$longitude, 
                           lat = filteredData()$latitude,
                           popup = filteredData()$species_nor,
                           color = ~pal(filteredData()$species_nor),
                           label = ~species_nor, 
                           radius = 4, 
                           fillOpacity = 0.99)
    })
  }
)

Shiny applications not supported in static R Markdown documents

#Analysis 3: - another map with rare (n=1) species

create list of rare species with name matching original df_trees

species_rare <-  df_trees_species_count%>%
  filter(n == 1) %>%
  separate(species, sep = "::", remove = FALSE, into = c('species_lat', 'species_nor'))

use list of rare species to subset original df_trees and also group them by common first name (i.e family name) to reduce species number

df_trees_rare <- df_trees %>%
  filter(species_nor %in% species_rare$species_nor) %>%
  separate(species_lat, sep = " ", remove = FALSE, into = c('species_first', 'species_second', 'species_third'))
## Warning: Expected 3 pieces. Additional pieces discarded in 18 rows [5, 7, 8, 9,
## 10, 11, 12, 14, 16, 17, 25, 27, 28, 43, 58, 61, 62, 67].

plot map with ggmap

smap + geom_point(data = df_trees_rare, aes(x=longitude, y = latitude, col = species_first))

plot map using leaflet, to create a hover-over dot pop up with species name, given not enough colors to differentiate so many species

#map center
mlong = -122.4446
mlat  = 37.72


rare_species_vec <- unique(df_trees_rare$species_lat)
pal <- colorFactor('Paired', domain = rare_species_vec)

leaflet(data = df_trees_rare, 
                width = '100%', height = 800,
                options = leafletOptions(minZoom = 9, maxZoom = 18)) %>% 
        addTiles() %>%
        setView(lng = mlong, lat = mlat, zoom = 12) %>%
        addCircleMarkers(lng = df_trees_rare$longitude, 
                         lat = df_trees_rare$latitude,
                         popup = df_trees_rare$species_lat,
                         label = df_trees_rare$species_lat, 
                         radius = 4,
                         fillOpacity = .5)